package com.tgy.thread;

import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-08-28 11:34
 */
public class ThreadStatus {

    /**
     *
     * 1. NEW
     * 2. RUNNABLE
     * 3. BLOCKED
     * 4. WAITING
     * 5. TIMED_WAITING
     * 6. TERMINATED
     */

    private Thread thread1;
    private Thread thread2;
    private Thread thread3;
    private Thread thread4;
    private Thread thread5;
    private Thread thread6;

    public ThreadStatus(){

        thread1 = new Thread(()->{

        },"thread1");

        thread2 = new Thread(()->{

                synchronized (this){

                    while (true){

                    }
                }

        },"thread1");

        thread3 = new Thread(()->{

            synchronized (this){



            }

        },"thread1");

        thread4 = new Thread(()->{

            try {
                thread2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"thread1");

        thread5 = new Thread(()->{


            try {
                TimeUnit.SECONDS.sleep(100000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        },"thread1");

        thread6 = new Thread(()->{

        },"thread1");

    }

    public void start() throws InterruptedException {

//        thread1.start();



        thread2.start();
        TimeUnit.SECONDS.sleep(1);
        thread3.start();

        thread4.start();

        thread5.start();

        thread6.start();


    }

    public void printThreadStatus(){


        System.out.println(thread1.getState());
        System.out.println(thread2.getState());
        System.out.println(thread3.getState());
        System.out.println(thread4.getState());
        System.out.println(thread5.getState());
        System.out.println(thread6.getState());

    }

    public static void main(String[] args) throws InterruptedException {

//        Thread.State.RUNNABLE

        ThreadStatus threadStatus = new ThreadStatus();

        threadStatus.start();

        threadStatus.printThreadStatus();

    }
}
